I have a WP page with embedded iframes. There is a widhet that changes the style of the page, and I need that it also changes the style of all embedded iframes. The style changes by clicking the button that has the following event handler:
NightVersionButton.click(function (event) {
// this is a part that changes the page style (and it works)
event.preventDefault();
Cookies.set('contrast', 'night', { expires: 7, path: window.cookiePath });
body.removeClass('highcontrast highcontrast2 highcontrast3');
body.addClass('night');
// this is a part that should change the style of all iframes, but it does not work due to the error "Uncaught TypeError: single_iframe.contentDocument.body.addClass is not a function"
var all_iframes = document.getElementsByTagName('iframe');
for (let single_iframe of all_iframes) {
var iframe_doc = single_iframe.contentWindow ? single_iframe.contentWindow.document : single_iframe.contentDocument;
iframe_doc.body.addClass('night');
//$(single_iframe).contents().find('body').addClass('night'); // this jQuery alternative does not work neither
}
});
However, the part of the JS code responsible for changing the styles in all iframes does not work, with the console error "Uncaught TypeError: single_iframe.contentDocument.body.addClass is not a function".
Please could you suggest the correct solution on how to change the JS that it will also apply addClass to all iframes?